package ui.graphs
{
	/**
	* This clas handles the "Motion" Graph
	* and parsing all of the point data from
	* dummyData.xml file into graph. 
	*/	
	import data.LoadDummyData;
	
	import events.Static_EventDispatcher;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import utils.StringUtils;
	
	public class MotionINIT extends MovieClip
	{
		private var _g 			: Graph;
		private var _ld 		: LoadDummyData;
		private var _xmlArr		: Array;
		
		/**
		 * Listening for when the LoadDummyData class has
		 * finished loading xml file. 
		 * 
		 */		
		public function MotionINIT()
		{
			_ld = new LoadDummyData();
			_ld.addEventListener(LoadDummyData.XML_LOADED, _parseXML);
			_ld.init("dummyData.xml");
		}
		
		/**
		 * Parses the "dummyData.xml" and puts data into an array.
		 * 
		 * @param $e : Event
		 */	
		private function _parseXML($e : Event) : void
		{
			_xmlArr = new Array();
			var tempStr : String = _ld.data..motion.@points;
			for (var i : Number = 0; i < 60; i++)
			{
				var numStr : String = StringUtils.beforeFirst(tempStr, ",");
				_xmlArr.push(numStr);
				
				if (i < 59)
					tempStr = StringUtils.afterFirst(tempStr, numStr + ",");
				else
				{
					_xmlArr.pop();
					_xmlArr.push(tempStr);
				}
			}
			
			_init();
		}
		
		/**
		 * Below are the different Eases used for the 3 different
		 * graphs.
		 * 
		 * SINE_EASE/SINE_EASE/QUAD_EASE: Motion Graph
		 * LINEAR_EASE/LINEAR/EASE: People Graph
		 * SINE_EASE/SINE_EASE/QUAD_EASE: Audio Graph
		 */
		private function _init() : void	
		{
			_g = new Graph(125, Graph.MOTION_GRAPH, Graph.SINE_EASE, Graph.QUAD_EASE, 1, 1, this.x, this.y, _xmlArr);
			addChild(_g);
			
			Static_EventDispatcher.addEventListener(Graph.CLEAN_UP, _cleanUp, false, 0, true);
			
			//var r1 : Reflect = new Reflect({mc: _g, alpha: 50, ratio: 50, distance: 0, updateTime: 0, reflectionDropoff: 1});
		}
		
		private function _cleanUp($e:Event) : void
		{
			_g.cleanUp();
		}
	}
}